<?php

namespace App\Http\Controllers\API;

use App\Models\Content;

class ContentsController extends Controller
{
    public function index()
    {
        $model = Content::when(request('keyword'), function ($q){
            $q->where('title', 'like', '%'.request('keyword').'%');
        })
            ->when(request('subject_id'),function ($q) {
                $q->whereHas('subject', function ($query) {
                    $query->where('id', request('subject_id'));
                });
            })
            ->with('subject')
            ->orderByDesc('id')
            ->paginate();

        return \Response::success($model);
    }

    public function show($id)
    {
        if ($this->my->expired_at < strtotime('tomorrow')) {
            abort('403', '请充值');
        }

        $model = Content::findOrFail($id);

        return \Response::success($model);
    }
}
